﻿using OnlineMediaAnalyzer.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OnlineMediaAnalyzer.Controllers
{

    public struct ViewFeed {
        public int id;
        public string name;
        public ViewFeed(int id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }

    public struct ViewFeedParty
    {
        public int id;
        public int partyId;
        public int feedId;
        public DateTime date;
        public int articlesCount;
        public int articlesMemberCount;
        public int negArticlesCount;
        public int posArticlesCount;

        public ViewFeedParty(int id, int partyId, int feedId, DateTime date, int articlesCount, int articlesMemberCount, int negArticlesCount, int posArticlesCount)
        {
            this.id = id;
            this.partyId = partyId;
            this.feedId = feedId;
            this.date = date;
            this.articlesCount = articlesCount;
            this.articlesMemberCount = articlesMemberCount;
            this.negArticlesCount = negArticlesCount;
            this.posArticlesCount = posArticlesCount;
        }
    }

    public struct ViewFeedStatistic
    {
        public int id;
        public int feedId;
        public DateTime date;
        public int articlesCount;
        public int politicalArticlesCount;
        public int multiPartyArticlesCount;
        public int partyMentionsCount;
        public int negPoliticalArticlesCount;
        public int posPoliticalArticlesCount;

        public ViewFeedStatistic(int id, int feedId, DateTime date, int articlesCount, int politicalArticlesCount, int multiPartyArticlesCount, int partyMentionsCount, int negPoliticalArticlesCount, int posPoliticalArticlesCount)
        {
            this.id = id;
            this.feedId = feedId;
            this.date = date;
            this.articlesCount = articlesCount;
            this.politicalArticlesCount = politicalArticlesCount;
            this.multiPartyArticlesCount = multiPartyArticlesCount;
            this.partyMentionsCount = partyMentionsCount;
            this.negPoliticalArticlesCount = negPoliticalArticlesCount;
            this.posPoliticalArticlesCount = posPoliticalArticlesCount;
        }
    }

    public struct ViewMemberMention
    {
        public int id;
        public int feedId;
        public int partyMemberId;
        public DateTime date;
        public int mentionsCount;
        public int negMentionsCount;
        public int posMentionsCount;

        public ViewMemberMention(int id, int feedId, int partyMemberId, DateTime date, int mentionsCount, int negMentionsCount, int posMentionsCount)
        {
            this.id = id;
            this.feedId = feedId;
            this.partyMemberId = partyMemberId;
            this.date = date;
            this.mentionsCount = mentionsCount;
            this.negMentionsCount = negMentionsCount;
            this.posMentionsCount = posMentionsCount;
        }
    }

    public struct ViewPartyMember
    {
        public int id;
        public int partyId;
        public string name;

        public ViewPartyMember(int id, int partyId, string name)
        {
            this.id = id;
            this.partyId = partyId;
            this.name = name;
        }
    }

    public struct ViewParty
    {
        public int id;
        public string name;
        public ViewParty(int id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }


    public class HomeController : Controller
    {
        private OnlineMediaAnalyzerContext db = new OnlineMediaAnalyzerContext();

        public ActionResult Index()
        {
            List<ViewFeed> viewFeeds = new List<ViewFeed>();
            foreach (var c in db.Feeds)
            {
                viewFeeds.Add(new ViewFeed(c.ID, c.Channel.Name));
            }
            ViewBag.Feeds = viewFeeds;

            List<ViewParty> viewParties = new List<ViewParty>();
            foreach (var c in db.Parties)
            {
                viewParties.Add(new ViewParty(c.ID, c.Name));
            }
            ViewBag.Parties = viewParties;

            List<ViewFeedParty> viewFeedParties = new List<ViewFeedParty>();
            foreach (var c in db.FeedParties)
            {
                viewFeedParties.Add(new ViewFeedParty(c.ID, c.PartyID, c.FeedID, c.Date, c.ArticlesCount, c.ArticlesMemberCount, c.NegArticlesCount, c.PosArticlesCount));
            }
            ViewBag.FeedParties = viewFeedParties;

            List<ViewFeedStatistic> viewFeedStatistics = new List<ViewFeedStatistic>();
            foreach (var c in db.FeedStatistics)
            {
                viewFeedStatistics.Add(new ViewFeedStatistic(c.ID, c.FeedID, c.Date, c.ArticlesCount, c.PoliticalArticlesCount, c.MultiPartyArticlesCount, c.PartyMentionsCount, c.NegPoliticalArticlesCount, c.PosPoliticalArticlesCount));
            }
            ViewBag.FeedStatistics = viewFeedStatistics;

            List<ViewMemberMention> viewMemberMentions = new List<ViewMemberMention>();
            foreach (var c in db.MemberMentions)
            {
                if (c.MentionsCount > 0)
                    viewMemberMentions.Add(new ViewMemberMention(c.ID, c.FeedID, c.PartyMemberID, c.Date, c.MentionsCount, c.NegMentionsCount, c.PosMentionsCount));
            }
            ViewBag.MemberMentions = viewMemberMentions;
            
            List<ViewPartyMember> viewPartyMembers = new List<ViewPartyMember>();
            foreach (var c in db.PartyMembers)
            {
                viewPartyMembers.Add(new ViewPartyMember(c.ID, c.PartyID, c.Name));
            }
            ViewBag.PartyMembers = viewPartyMembers;


            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}